package main

import (
	"context"
	"encoding/json"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/public"
	public2 "git.900sui.cn/kc/rpcinterface/interface/public"
	"git.900sui.cn/kc/rpcinterface/interface/task"
	"github.com/streadway/amqp"
)

//发送短信
func main() {
	logs.Info("Environment Variable:MSF_ENV:",kcgin.KcConfig.RunMode)
	rpcSms := new(public.Sms).Init()
	defer rpcSms.Close()

	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("queue.sendSms"), func(msg amqp.Delivery) {
		var smsData task.SendSmsParams
		err := json.Unmarshal( msg.Body, &smsData )
		if err != nil{
			return
		}

		ctx := context.Background()
		var reply = false
		if smsData.Type == task.SEND_SMS_TYPE_captcha{
			//发送验证码
			args := &public2.SendCaptchaParams{
				Phone:smsData.Phone,
				CheckSendNum:smsData.CheckSendNum,
			}
			err := rpcSms.SendCaptcha( ctx, args, &reply )
			if err != nil{
				logs.Info("错误", err)
				return
			}
		}
		if smsData.Type == task.SEND_SMS_TYPE_plain{
			//发送普通短信
			args := &public2.SendSmsParams{
				Phone:smsData.Phone,
				MsgStr:smsData.MsgStr,
			}
			err := rpcSms.SendSms( ctx, args, &reply )
			if err != nil{
				return
			}
		}

		return
	})
	if err != nil {
		panic(err)
	}
}
